﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Mail;
using System.Configuration;

namespace Infinite.Systems.Util.Library.Messaging
{
    /// <summary>
    /// Holds Method for Sending Email
    /// </summary>
    public class Mail
    {

        /// <summary>
        /// Sends the specified message to the 
        /// </summary>
        /// <param name="email">Email Packet Object</param>
        public static void SendEmail(EmailPacket email)
        {


            string host = Mail.Host != null ? Host : ConfigurationManager.AppSettings["SmtpHost"].ToString(); 
            MailMessage mailMessage = new MailMessage(email.MailFrom, email.EmailRecipient, email.Subject, email.BodyContent);
            Attachment attachment = new Attachment("Attachment.png");
            mailMessage.IsBodyHtml = true;
            mailMessage.Attachments.Add(attachment);
            SmtpClient mailClient = new SmtpClient(host);

            try
            {
                mailClient.Send(mailMessage);

            }
            catch (Exception ex)
            {
                //Log but not rethrow the error
                
            }

        }
        /// <summary>
        /// Host name of the SMTP Server
        /// </summary>
        public static string Host
        {
            get;
            set;
        }


    }


}
